package com.cec.home.service.impl

import com.mongodb.BasicDBObject
import com.mongodb.DBCollection
import com.mongodb.DBCursor
import org.springframework.stereotype.Service
/**
 * Created with IDEA
 * User:hxh
 * Date:16/4/18
 * Time:下午2:23
 */
@Service
class NewsServiceImpl extends BaseMongoServiceImpl{
    @Override
    DBCollection getColl() {
        return hdMongoTemplate.getCollection("news")
    }

    @Override
    List getAll(BasicDBObject query, BasicDBObject sort, BasicDBObject returnFiled, int size) {
        DBCursor cursor
        if (sort) {
            cursor = getColl().find(query, returnFiled).sort(sort).limit(size)
        } else {
            cursor = getColl().find(query, returnFiled).limit(size)
        }

        def list = new ArrayList()
        while (cursor.hasNext()) {
            list.add(cursor.next())
        }
        return list
    }
}
